package com.itheima.guava.samples.demo.CollectionsDemo;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListTest {

    public static void main(String[] args) {

        testLists();
    }

    public static void testLists() {

        String str = "i love u";
        String[] strs = {"i like u", "i miss u"};


        List<String> list = Lists.asList(str, strs);
        System.out.println(list);

        /**
         * transform：根据传进来的function对fromList进行相应的处理
         * 并将处理得到的结果存入到新的list对象中返回
         */

        List<String> transform = Lists.transform(list, new Function<String, String>() {

            @Override
            public String apply(String input) {
                return input.toUpperCase();
            }
        });

        System.out.println(transform);

        /**
         * partition：根据size传入的List进行切割，切割成符合要求的小的List
         * 并将这些小的List存入一个新的List对象中返回
         */
        List<List<String>> partition = Lists.partition(list, 2);
        System.out.println(partition);

        /**
         * charactersOf：将传进来的String或者CharSequence分割为单个的字符
         * 并存入到一个ImmutableList对象中返回
         * ImmutableList：一个高性能、不可变的、随机访问列表的实现
         */
        ImmutableList<Character> characters = Lists.charactersOf("realfighter");
        System.out.println(characters);//[r, e, a, l, f, i, g, h, t, e, r]

        /**
         * reverse：返回一个传入List内元素倒序后的List
         */
        List<String> reverse = Lists.reverse(list);
        System.out.println(reverse);//[i hate u, i like u, i love u]

        List<Integer> newArrayList = Lists.newArrayList();
        newArrayList.add(1);
        newArrayList.add(2);
        newArrayList.add(3);
        newArrayList.add(4);
        newArrayList.add(5);

        System.out.println(newArrayList);

        CopyOnWriteArrayList<String> copyOnWriteArrayList = Lists.newCopyOnWriteArrayList();
        LinkedList<String> linkedList = Lists.newLinkedList();
    }
}
